package com.qcby.shujia.demo.common.web;

/**
 * @className: ResultData
 * @description: 统一返回格式
 * @author: whz
 * @date: 2021/9/23
 **/
public class ResultData {
    public final static int CODE_OK=200;
    public final static int CODE_ERROR=500;
    private int code;
    private String msg;

    public static ResultData ok(){
        return ok(null);
    }

    public static ResultData ok(Object data){
        return ok(null,data);
    }

    public static ResultData ok(String msg){
        return ok(msg,null);
    }

    public static ResultData ok(String msg, Object data){
        return new ResultData(CODE_OK,msg,data);
    }



    public static ResultData error(){
        return error(null);
    }

    public static ResultData error(Object data){
        return error(null,data);
    }

    public static ResultData error(String msg){
        return error(msg,null);
    }

    public static ResultData error(String msg, Object data){
        return new ResultData(CODE_ERROR,msg,data);
    }

    //对外隐藏，只能通过固定格式初始化对象
    private ResultData(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static int getCodeOk() {
        return CODE_OK;
    }

    public static int getCodeError() {
        return CODE_ERROR;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    private Object data;
}
